import { optimize, OptimizedSvg, OptimizeOptions, OptimizedError } from 'svgo';

function svgOptimize(
    svgString: string | Buffer,
    options?: OptimizeOptions,
): OptimizedSvg | OptimizedError {
    const defaultConfig: OptimizeOptions = {
        plugins: [
            'removeDoctype',
            'removeXMLProcInst',
            'removeComments',
            'removeMetadata',
            'removeEditorsNSData',
            'cleanupAttrs',
            'convertStyleToAttrs',
            'cleanupIDs',
            'removeRasterImages',
            'removeUselessDefs',
            'cleanupNumericValues',
            'cleanupListOfValues',
            'convertColors',
            'removeUnknownsAndDefaults',
            'removeNonInheritableGroupAttrs',
            'removeUselessStrokeAndFill',
            'removeViewBox',
            'cleanupEnableBackground',
            'removeHiddenElems',
            'removeEmptyText',
            'convertShapeToPath',
            'moveElemsAttrsToGroup',
            'moveGroupAttrsToElems',
            'collapseGroups',
            'convertPathData',
            'convertTransform',
            'removeEmptyAttrs',
            'removeEmptyContainers',
            'mergePaths',
            'removeUnusedNS',
            //'transformsWithOnePath',
            'sortAttrs',
            'removeTitle',
            'removeDesc',
            'removeDimensions',
            //'removeAttrs',
            //'addClassesToSVGElement',
            'removeStyleElement',
        ],
    };

    return optimize(svgString, { ...defaultConfig, ...options });
}

export { svgOptimize };
